/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.ember.ezsp.structure;

import java.util.HashMap;
import java.util.Map;

/**
 * Class to implement the Ember Enumeration <b>EmberZigbeeCommandType</b>.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public enum EmberZigbeeCommandType {
    /**
     * Default unknown value
     */
    UNKNOWN(-1),

    /**
     * Describes an 802.15.4 MAC layer command.
     */
    EMBER_ZIGBEE_COMMAND_TYPE_MAC(0x0000),

    /**
     * Describes a ZigBee Network layer command.
     */
    EMBER_ZIGBEE_COMMAND_TYPE_NWK(0x0001),

    /**
     * Describes a ZigBee Application Support layer command.
     */
    EMBER_ZIGBEE_COMMAND_TYPE_APS(0x0002),

    /**
     * Describes a ZigBee Device Object command.
     */
    EMBER_ZIGBEE_COMMAND_TYPE_ZDO(0x0003),

    /**
     * Describes a ZigBee Cluster Library command.
     */
    EMBER_ZIGBEE_COMMAND_TYPE_ZCL(0x0004),

    /**
     * Although a beacon is not a MAC command, we have it here for simplicity.
     */
    EMBER_ZIGBEE_COMMAND_TYPE_BEACON(0x0005);

    /**
     * A mapping between the integer code and its corresponding type to
     * facilitate lookup by code.
     */
    private static Map<Integer, EmberZigbeeCommandType> codeMapping;

    private int key;

    static {
        codeMapping = new HashMap<Integer, EmberZigbeeCommandType>();
        for (EmberZigbeeCommandType s : values()) {
            codeMapping.put(s.key, s);
        }
    }

    private EmberZigbeeCommandType(int key) {
        this.key = key;
    }

    /**
     * Lookup function based on the EmberStatus type code. Returns null if the
     * code does not exist.
     *
     * @param code the code to lookup
     * @return enumeration value of the alarm type.
     */
    public static EmberZigbeeCommandType getEmberZigbeeCommandType(int code) {
        if (codeMapping.get(code) == null) {
            return UNKNOWN;
        }

        return codeMapping.get(code);
    }

    /**
     * Returns the EZSP protocol defined value for this enumeration.
     *
     * @return the EZSP protocol key
     */
    public int getKey() {
        return key;
    }
}
